package com.sgx.learning.luban.homework.attributes;

import com.sgx.learning.luban.homework.attributes.ext.stackmapframe.StackMapFrame;
import com.sgx.learning.luban.homework.basictype.U1;
import com.sgx.learning.luban.homework.basictype.U2;
import com.sgx.learning.luban.homework.basictype.U4;
import com.sgx.learning.luban.homework.constantpool.ConstantPoolInfo;
import lombok.Data;

import java.io.IOException;
import java.io.InputStream;

@Data
public class StackMapTable extends AttributeInfo {

    private int numberOfEntries;

    private StackMapFrame[] stackMapTables;

    @Override
    public void read(InputStream is, ConstantPoolInfo[] constantPoolInfos) throws IOException {
        this.numberOfEntries = U2.read(is).getValue();
        if(this.numberOfEntries > 0) {
            stackMapTables = new StackMapFrame[numberOfEntries];
            for (int i = 0; i < numberOfEntries; i++) {
                StackMapFrame temp = StackMapFrame.selectStackMapFrame(is,constantPoolInfos);
                stackMapTables[i] = temp;
//                short offsetDelta = U2.read(is).getValue();
//                for (int j = 0; j < 2; j++) {
//                    short size = U2.read(is).getValue();
//                    for (int k = 0; k < size; k++) {
//                        StackMapFrame temp = StackMapFrame.selectStackMapFrame(is,constantPoolInfos);
//                    }
//                }
            }
        }
    }
}
